package com.funcourse.demo.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import java.util.List;
import lombok.Data;
import org.springframework.util.StringUtils;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Question {

  /**
   * the number in a quesion suit
   */
  @ApiModelProperty("题号")
  Integer questionNumber;
  @ApiModelProperty("题干")
  String questionStem;
  @ApiModelProperty("答案解析")
  String answerExplanation;
  @ApiModelProperty("题目图片，废弃字段，用image代替")
  String questionCoverUrl;
  @ApiModelProperty("题目图片")
  Image image;
  @ApiModelProperty("选择题选项")
  List<Choice> choices;
  @ApiModelProperty("填空题备选答案，第0个为主答案")
  List<String> rightAnswers;
  @ApiModelProperty("限时秒单位")
  Integer timeLimit;
  @ApiModelProperty("是否多选，废弃字段")
  Boolean isMultiSel=false;
  @ApiModelProperty("题目类型")
  QuestionType questionType;
  public QuestionType getQuestionType(){
    if(null == this.questionType && null != isMultiSel){
      return isMultiSel?QuestionType.SEL_MULTI:QuestionType.SEL_SINGLE;
    }
    return this.questionType;
  }
  public enum QuestionType {
    /**
     * 单选
     */
    SEL_SINGLE,
    /**
     * 多选
     */
    SEL_MULTI,
    /**
     * 填空
     */
    BLANK,
    /**
     * 简答
     */
    ANSWER,
    /**
     * 判断
     */
    TF;
  }
  //兼容 questionCoverUrl
  public Image getImage(){
    if(null == image){
      this.image = new Image(questionCoverUrl,questionCoverUrl);
    }
    return image;
  }
  public String getQuestionCoverUrl(){
    return null;
  }
}
